package main

import (
	"fmt"
	"math"
)

func commonChars(words []string) []string {
	size := 26
	bucket := make([]int, size)
	res := make([]string, 0)
	for i := 0; i < size; i++ {
		bucket[i] = math.MaxInt
	}
	for _, v := range words {
		b2 := make([]int, size)
		for i := 0; i < len(v); i++ {
			b2[v[i]-'a']++
		}
		for i := 0; i < size; i++ {
			if b2[i] < bucket[i] {
				bucket[i] = b2[i]
			}
		}
	}
	for i := 0; i < size; i++ {
		for bucket[i] > 0 {
			res = append(res, string(i+'a'))
			bucket[i]--
		}
	}
	return res
}

func main() {
	fmt.Println(commonChars([]string{"bella", "label", "roller"}))
}
